package com.mall.service.mallCategory;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.mallCategory.MallCategoryService;
import com.mall.custom.dao.read.MallCategoryReadMapper;
import com.mall.custom.dao.write.MallCategoryWriteMapper;
import com.mall.pojo.MallCategory;
import com.mall.pojo.MallCategoryExample;
import com.mall.pojo.MallCategoryExample.Criteria;


@Service
public class MallCategoryServiceImpl implements MallCategoryService {

	@Autowired
	private MallCategoryReadMapper mallCategoryReadMapper;
	@Autowired
	private MallCategoryWriteMapper mallCategoryWriteMapper;


	@Override
	public List<MallCategory> getMallCategoryList(MallCategoryExample example) {
		return this.mallCategoryReadMapper.selectByExample(example);
	}

	@Override
	public MallCategory getMallCategoryById(Integer categoryId) {
		return this.mallCategoryReadMapper.selectByPrimaryKey(categoryId);
	}

	@Override
	public List<MallCategory> getSecMallCategoryListByParentMallCategoryId(Integer categoryId) {
		MallCategoryExample example =  new MallCategoryExample();
		Criteria criteria = example.createCriteria();
		criteria.andParentIdEqualTo(categoryId);
		criteria.andStatusEqualTo(0);
		return this.mallCategoryReadMapper.selectByExample(example);
	}

	@Override
	public int modifyMallCategoryByMallCategory(MallCategory mallCategory) {
		return this.mallCategoryWriteMapper.updateByPrimaryKey(mallCategory);
	}

	@Override
	public int deleteMallCategoryByCategoryId(Integer categoryId) {
		return this.mallCategoryWriteMapper.deleteByPrimaryKey(categoryId);
	}

	@Override
	public int addMallCategoryByMallCategory(MallCategory mallCategory) {
		mallCategory.setGmtCreate(new Date());
		mallCategory.setGmtModify(new Date());
		return this.mallCategoryWriteMapper.insert(mallCategory);
	}

	@Override
	public List<MallCategory> getFirstMallCategoryListByKey(Integer onlyKey) {
		MallCategoryExample example =  new MallCategoryExample();
		Criteria criteria = example.createCriteria();
		criteria.andCommOnlyKeyEqualTo(onlyKey);
		criteria.andParentIdEqualTo(0);
		criteria.andStatusEqualTo(0);
		return this.mallCategoryReadMapper.selectByExample(example);
	}

	@Override
	public int updateStatusByIds(List<Integer> ids) {
		return this.mallCategoryWriteMapper.updateStatusByIds(ids);
	}

	

}
